package com.dxb.test.thread;

/**
 * ClassName：com.dxb.test.thread.ABC2 <br>
 * Description：TODO <br>
 *
 * @author 戴晓波 <br>
 * Date 2022/2/14/014 13:49 <br>
 * @version v1.0 <br>
 */
public class ABC2 {
    private int num;

    public void print(int index) {
        for (int i = 0; i < 10; ) {
            synchronized (this) {
                while (num % 3 == index) {
                    i++;
                    num++;
                    System.out.println(Thread.currentThread().getName());
                }
            }
        }
    }

    public static void main(String[] args) {
        ABC2 abc = new ABC2();
        new Thread(()->abc.print(0),"A").start();
        new Thread(()->abc.print(1),"B").start();
        new Thread(()->abc.print(2),"C").start();

    }
}
